function checkNick(){ // проверяем ник на занятость при регистрации
	var obj=$('#regnick').attr('value');
	var oby=$('#regmail').attr('value');
	if (obj.length==0 || oby=='e-mail' || oby.length==0){
		$('#freenick').html('<span style="color: red;">X</span>');
		$('#regsubmit').attr('disabled','disabled');
	}
	else
		$.get(
		      '/', {action: 'checkNick', login: obj},
		      function (data){
			if (data=='1'){
				$('#freenick').html('<span style="color: red;">X</span>');
				$('#regsubmit').attr('disabled','disabled');
			}
			else {
				$('#freenick').html('<span style="color: green;">&radic;</span>');
				$('#regsubmit').removeAttr('disabled');
			}
		      }
		);
}


function showLoginTab(q){ // показываем вкладку для логина
	$('#upload_overlay').show();
	var obj=document.getElementById('logintab');
	obj.style.display='block'; obj.style.position='fixed';
	var x=screen.width; x=x-obj.clientWidth; x=Math.round(x/2);
	obj.style.left=x+"px"; obj.style.top="100px";
	if (q!=undefined)$('#urltogo').attr('value',q);
	if (q!=undefined)$('#urltogo2').attr('value',q);
}



function hideLoginTab(){ // прячем вкладку для логина
	$('#upload_overlay').hide();
	$('#logintab').hide();
}





// набор всплывающих подсказов
function showMainHint(e, hint){
    if (hint!=''){
	obj = $('#hintdiv');
	$(obj).show();
	$(obj).html(hint);
	x=$(e).offset().left+$(e).width()+0; y=$(e).offset().top+25;
	$(obj).offset({ top: y, left: x});
	$(obj).fadeTo('fast', 0.9);
	$(obj).width(400);
	if ($(window).width() - $(obj).width()-$(obj).offset().left < 0 ){
		obj.offset({left: $(window).width() - $(obj).width()-50});
	}
    }
}
function hideMainHint(){
    $('#hintdiv').hide();
}



// аналог php-функции
function str_replace ( search, replace, subject ) {	// Replace all occurrences of the search string with the replacement string
	// 
	// +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
	// +   improved by: Gabriel Paderni

	if(!(replace instanceof Array)){
		replace=new Array(replace);
		if(search instanceof Array){//If search	is an array and replace	is a string, then this replacement string is used for every value of search
			while(search.length>replace.length){
				replace[replace.length]=replace[0];
			}
		}
	}

	if(!(search instanceof Array))search=new Array(search);
	while(search.length>replace.length){//If replace	has fewer values than search , then an empty string is used for the rest of replacement values
		replace[replace.length]='';
	}

	if(subject instanceof Array){//If subject is an array, then the search and replace is performed with every entry of subject , and the return value is an array as well.
		for(k in subject){
			subject[k]=str_replace(search,replace,subject[k]);
		}
		return subject;
	}

	for(var k=0; k<search.length; k++){
		var i = subject.indexOf(search[k]);
		while(i>-1){
			subject = subject.replace(search[k], replace[k]);
			i = subject.indexOf(search[k],i);
		}
	}

	return subject;

}



// аналог php-функции
function strpos( haystack, needle, offset){	// Find position of first occurrence of a string
	// 
	// +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)

	var i = haystack.indexOf( needle, offset ); // returns -1
	return i >= 0 ? i : false;
}



// аналог php-функции
function trim( str, charlist ) {	// Strip whitespace (or other characters) from the beginning and end of a string
	// 
	// +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
	// +   improved by: mdsjack (http://www.mdsjack.bo.it)
	// +   improved by: Alexander Ermolaev (http://snippets.dzone.com/user/AlexanderErmolaev)
	// +	  input by: Erkekjetter
	// +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)

	charlist = !charlist ? ' \s\xA0' : charlist.replace(/([\[\]\(\)\.\?\/\*\{\}\+\$\^\:])/g, '\$1');
	var re = new RegExp('^[' + charlist + ']+|[' + charlist + ']+$', 'g');
	return str.replace(re, '');
}


// аналог php-функции
function nl2br( str ) {	// Inserts HTML line breaks before all newlines in a string
	// 
	// +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)

	return str.replace(/([^>])\n/g, '$1<br/>');
}




// аналог php-функции
function explode( delimiter, string ) {	// Split a string by string
	// 
	// +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
	// +   improved by: kenneth
	// +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)

	var emptyArray = { 0: '' };

	if ( arguments.length != 2
		|| typeof arguments[0] == 'undefined'
		|| typeof arguments[1] == 'undefined' )
	{
		return null;
	}

	if ( delimiter === ''
		|| delimiter === false
		|| delimiter === null )
	{
		return false;
	}

	if ( typeof delimiter == 'function'
		|| typeof delimiter == 'object'
		|| typeof string == 'function'
		|| typeof string == 'object' )
	{
		return emptyArray;
	}

	if ( delimiter === true ) {
		delimiter = '1';
	}

	return string.toString().split ( delimiter.toString() );
}




// валидация е-мейла через регулярку. Тут указываются домены, нужно быть внимательным! Или переписать регулярку
function validate_email(email){
	var re = /^\w+([\.-]?\w+)*@(((([a-z0-9]{2,})|([a-z0-9][-][a-z0-9]+))[\.][a-z0-9])|([a-z0-9]+[-]?))+[a-z0-9]+\.([a-z]{2}|(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum|ru|su|ua))$/i;
	if(re.test(email))return true; 
	else return false; 
} 


